<?php
/**
 * XmuSlh, web platform of Student Association Federation of Xiamen University
 * 
 * Rewritting one or some pages of StatusNet. 
 * To get the original version, please visit <http://status.net/>.
 * 
 * StatusNet, the distributed open-source microblogging tool
 * 
 * LICENCE: This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Base class for LIKEs.
 * 
 * 用来显示一个人人喜欢和QQ喜欢的控件.
 * 
 * COULD use 'extraHead' for renren og:flag to share.
 * AS:
 * <meta property="og:site_name" content="煎蛋网" />
 * og:title			标题
 * og:type			类型. 类型请使用协议官方网站上Object types定义的类型. 
 * og:image			表示页面信息的一张缩略图地址. 
 * og:url			代表页面的规范url. 
 * og:description	关于页面信息的简短描述. 
 * og:site_name		页面所在的网站名称. 
 * og:videosrc		视频Flash地址
 * og:audiosrc		填写音频的.mp3地址
 * xn:page_id		填写需要关联的公共主页ID
 * 
 * @author		ytukie <ytukie@gmail.com>
 * @version		0.1
 */

// XmuSlh only.
if ( !defined('XMUSLH')) { exit(1); }

// Requirements.
require_once INSTALLDIR . '/lib/slh_widget.php';
require_once INSTALLDIR . '/lib/slh_util.php';


/**
 * Widget for displaying LIKEs.
 */
class Like extends Widget
{
	/**
	 * Page url of xiaonei.
	 */
	var $xn_url;
	
	/**
	 * Show faces of xiaonei.
	 */
	var $xn_showfaces;
	
	/**
	 * Site name of xiaonei.
	 */
	var $xn_site_name;
	
	/**
	 * Title of xiaonei.
	 */
	var $xn_title;
	
	/**
	 * Image of xiaonei.
	 */
	var $xn_image;
	
	/**
	 * Description of xiaonei.
	 */
	var $xn_description;
	
	/**
	 * Xiaonei like code slice.
	 */
	var $xncode;
	
	/**
	 * Qzone like code slice.
	 */
	var $qqcode;
	
	/**
	 * Constructor.
	 */
	function __construct($fields, 
						 $out)
	{
		parent::__construct($out);
		
		// Magically put fields into current scope.
		// For $xn_
		extract($fields);

		$this->xn_url 			= rawurlencode($xn_url);
		$this->xn_showfaces 	= $xn_showfaces;
		$this->xn_site_name 	= $xn_site_name;
		$this->xn_title			= $xn_title;
		$this->xn_image			= $xn_image;
		$this->xn_description	= $xn_description;
		
		$this->xncode = '<iframe src="http://www.connect.renren.com/like/v2?url='. 
						$this->xn_url .
						'&showfaces=' .
						$this->xn_showfaces .
						'" style="width:100px;height:22px;max-height:64px;" scrolling="no" frameborder="0" allowTransparency="true"></iframe>';
		
		$this->qqcode = '<a version="1.0" class="qzOpenerDiv" ' .
				  		'href="http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_likeurl" ' .
						'target="_blank">喜欢</a>' .
						'<script src="http://qzonestyle.gtimg.cn/qzone/app/qzlike/qzopensl.js' .
						'#jsdate=20110603&style=4&showcount=1&width=100&height=24"' .
						' charset="utf-8" defer="defer"></script>';
	}
	
	/**
	 * Show the LIKEs.
	 */
	function show()
	{
		$this->out->elementStart('div', 'likes');
		
		$this->out->elementStart('ul');
		$this->out->elementStart('li', 'qqlike');
		$this->out->raw($this->qqcode);
		$this->out->elementEnd('li');
		
		$this->out->elementStart('li', 'xnlike');
		$this->out->raw($this->xncode);
		$this->out->elementEnd('li');
		
		$this->out->elementEnd('ul');
		$this->out->elementEnd('div');
	}
	
	/**
	 * Show the <meta></meta>
	 */
	function showMetas()
	{
		$this->out->raw('<meta http-equiv="content-type" content="text/html;charset=UTF-8">');
		$this->out->element('meta', array('property' => 'og:site_name',
									 	  'content' => $this->xn_site_name));
		$this->out->element('meta', array('property' => 'og:title',
									 	  'content' => htmlspecialchars($this->xn_title)));
		$this->out->element('meta', array('property' => 'og:image',
									 	  'content' => $this->xn_image));
		$this->out->element('meta', array('property' => 'og:description',
										  'content' => htmlspecialchars($this->xn_description)));
		$this->out->element('meta', array('property' => 'xn:page_id',
										  'content' => '600215140'));
	}
	
}

?>